package com.blog.blogservice.api.controller.v1;

import com.blog.blogservice.app.service.LabelService;
import com.blog.blogservice.domain.entity.BaseResponse;
import com.blog.blogservice.domain.entity.Label;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 标签表(Label)表控制层
 *
 * @author guanglin.ma
 * @since 2024-03-02 23:25:50
 */

@RestController("labelController.v1")
@RequestMapping("/v1/labels")
@RequiresPermissions("admin")
public class LabelController {


    @Autowired
    private LabelService labelService;

    //    标签表列表
    @GetMapping("/list/label")
    public BaseResponse<List<Label>> list(Label label) {
        List<Label> list = labelService.selectList(label);
        return new BaseResponse<>("20000", list);
    }

    //    标签表明细
    @GetMapping("/{labelId}")
    public ResponseEntity<Label> detail(@PathVariable Long labelId) {

        return null;
    }

    //    创建标签表
    @PostMapping("/new/labels")
    public BaseResponse<List<Label>> save(@RequestBody List<Label> labels) {
        List<Label> resultList = this.labelService.saveData(labels);
        return new BaseResponse("20000", resultList);
    }

    //    删除标签表
    @DeleteMapping("/abandon/labels")
    public BaseResponse<?> remove(@RequestBody List<Label> labels) {
        this.labelService.deleteData(labels);
        return BaseResponse.ok();
    }

}

